<template>
	<div class="addProject business-workAdd">
		<div class="addForm zll-form">
			<el-form :model="addForm" :rules="rules" ref="addForm" class="demo-ruleForm">
				<el-form-item class="formList" prop="deviceCode" label="设备号：">
					<el-select disabled clearable class="input_right" v-model="addForm.deviceCode" placeholder="设备号">
						<el-option v-for="(item,index) in deviceList" :key="index" :label="item.deviceCode"
								   :value="item.deviceCode" />
					</el-select>
				</el-form-item>
				<el-form-item class="formList" prop="sterilizeUserName" label="操作工：">
					<el-select clearable class="input_right" v-model="addForm.sterilizeUserName" placeholder="操作工">
						<el-option v-for="(item,index) in userList" :key="index" :label="item.userName"
								   :value="item.userName"/>
					</el-select>
				</el-form-item>
			</el-form>
		</div>
	</div>
</template>
<script>
	export default {
		props: ['editData'],
		data() {
			return {
				addForm: {
					id: '',
					deviceCode: '',
					sterilizeUserName: '',
					tabName: 'U管成型',
					sterilizeType: '1',
					sterilizeWater: '75%酒精',
				},
				rules: {
					deviceCode: [
						{required: true, message: '请选择设备号', trigger: 'change'},
					],
					sterilizeUserName: [
						{required: true, message: '请选择操作工', trigger: 'change'},
					],
				},
				count: 0,
				deviceList: [],
				userList: [],
			}
		},
		methods: {
			submitForm() {
				let self = this;
				this.$refs["addForm"].validate((valid) => {
					if (valid) {
						self.operate();
					} else {
						return false;
					}
				});
			},
			operate() {
				let self = this;
				if (this.count == 0) {
					let url = self.addForm.id?'/jinl/sterilize/updateSterilize':'/jinl/sterilize/addSterilize';
					self.count++;
					let param = Object.assign({},self.addForm);
					param.sterilizeStatus = '1';
					self.$http({
						url: url,
						method: "post",
						params: param,
					}).then(resp => {
						if (resp.success) {
							self.$message.success('操作成功');
							self.$eventBus.$emit('updateSterilizeList');
							self.$refs["addForm"].clearValidate();
							return
						}
						self.$message.error(resp.message);
						self.count--;
					});
				}
			},

			// getDeviceSelect() {//获取表格数据
			// 	let self = this;
			// 	self.deviceList = [];
			// 	self.$http({
			// 		url: "/jinl/device/getDeviceSelect",
			// 		method: "post",
			// 		data: JSON.stringify({processName: 'U管成型', deviceStatus: '0'}),
			// 		dataType: 'json',
			// 		contentType: 'application/json',
			// 	}).then(resp => {
			// 		if (resp.success) {
			// 			self.deviceList = resp.result;
			// 		}
			// 	})
			// },

			getSelectUsers() {
				let self = this;
				self.userList = [];
				self.$http({
					url: "/jinl/login/getLoginSelectList",
					method: "post",
				}).then(resp => {
					if (resp.success) {
						self.userList = resp.result;
					}
				});
			},
		},
		watch: {
			editData(val) {
				for (let key in this.addForm) {
					this.addForm[key] = val[key] || this.addForm[key];
				}
				this.$refs["addForm"].clearValidate();
			}
		},
		mounted() {
			this.getSelectUsers();
			// this.getDeviceSelect();
		},
		components: {}
	}
</script>
<style lang="scss" scoped>
	@import "@/style/dialog.scss";

</style>